package logic

import (
	"context"
	"fmt"
	"health/model/mysql"

	"health/registerrpc/internal/svc"
	"health/registerrpc/registerrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *registerrpc.AddRequest) (*registerrpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	var add = mysql.Register{
		Doctor: in.Doctor,
		Price:  float64(in.Price),
		Times:  in.Times,
		Types:  in.Types,
	}
	err := mysql.DB.Debug().Create(&add).Error
	if err != nil {
		return nil, fmt.Errorf("预约添加失败")
	}

	return &registerrpc.AddResponse{Id: int64(add.ID)}, nil
}
